
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>14.3 使用AddressSanifier向CDash报告内存缺陷 · 《CMake Cookbook》中文版</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="陈晓伟 chenxiaowei">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="14.4-chinese.html" />
    
    
    <link rel="prev" href="14.2-chinese.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../preface/preface-chinese.html">
            
                <a href="../preface/preface-chinese.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter0/0.0-chinese.html">
            
                <a href="../chapter0/0.0-chinese.html">
            
                    
                    第0章 配置环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter0/0.1-chinese.html">
            
                <a href="../chapter0/0.1-chinese.html">
            
                    
                    0.1 获取代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter0/0.2-chinese.html">
            
                <a href="../chapter0/0.2-chinese.html">
            
                    
                    0.2 Docker镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter0/0.3-chinese.html">
            
                <a href="../chapter0/0.3-chinese.html">
            
                    
                    0.3 安装必要的软件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter0/0.4-chinese.html">
            
                <a href="../chapter0/0.4-chinese.html">
            
                    
                    0.4 测试环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter0/0.5-chinese.html">
            
                <a href="../chapter0/0.5-chinese.html">
            
                    
                    0.5 上报问题并提出改进建议
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter1/1.0-chinese.html">
            
                <a href="../chapter1/1.0-chinese.html">
            
                    
                    第1章 从可执行文件到库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter1/1.1-chinese.html">
            
                <a href="../chapter1/1.1-chinese.html">
            
                    
                    1.1 将单个源文件编译为可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter1/1.2-chinese.html">
            
                <a href="../chapter1/1.2-chinese.html">
            
                    
                    1.2 切换生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter1/1.3-chinese.html">
            
                <a href="../chapter1/1.3-chinese.html">
            
                    
                    1.3 构建和链接静态库和动态库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter1/1.4-chinese.html">
            
                <a href="../chapter1/1.4-chinese.html">
            
                    
                    1.4 用条件句控制编译
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../chapter1/1.5-chinese.html">
            
                <a href="../chapter1/1.5-chinese.html">
            
                    
                    1.5 向用户显示选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../chapter1/1.6-chinese.html">
            
                <a href="../chapter1/1.6-chinese.html">
            
                    
                    1.6 指定编译器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../chapter1/1.7-chinese.html">
            
                <a href="../chapter1/1.7-chinese.html">
            
                    
                    1.7 切换构建类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../chapter1/1.8-chinese.html">
            
                <a href="../chapter1/1.8-chinese.html">
            
                    
                    1.8 设置编译器选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../chapter1/1.9-chinese.html">
            
                <a href="../chapter1/1.9-chinese.html">
            
                    
                    1.9 为语言设定标准
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../chapter1/1.10-chinese.html">
            
                <a href="../chapter1/1.10-chinese.html">
            
                    
                    1.10 使用控制流
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter2/2.0-chinese.html">
            
                <a href="../chapter2/2.0-chinese.html">
            
                    
                    第2章 检测环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter2/2.1-chinese.html">
            
                <a href="../chapter2/2.1-chinese.html">
            
                    
                    2.1 检测操作系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter2/2.2-chinese.html">
            
                <a href="../chapter2/2.2-chinese.html">
            
                    
                    2.2 处理与平台相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter2/2.3-chinese.html">
            
                <a href="../chapter2/2.3-chinese.html">
            
                    
                    2.3 处理与编译器相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter2/2.4-chinese.html">
            
                <a href="../chapter2/2.4-chinese.html">
            
                    
                    2.4 检测处理器体系结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../chapter2/2.5-chinese.html">
            
                <a href="../chapter2/2.5-chinese.html">
            
                    
                    2.5 检测处理器指令集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../chapter2/2.6-chinese.html">
            
                <a href="../chapter2/2.6-chinese.html">
            
                    
                    2.6 为Eigen库使能向量化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter3/3.0-chinese.html">
            
                <a href="../chapter3/3.0-chinese.html">
            
                    
                    第3章 检测外部库和程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter3/3.1-chinese.html">
            
                <a href="../chapter3/3.1-chinese.html">
            
                    
                    3.1 检测Python解释器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter3/3.2-chinese.html">
            
                <a href="../chapter3/3.2-chinese.html">
            
                    
                    3.2 检测Python库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter3/3.3-chinese.html">
            
                <a href="../chapter3/3.3-chinese.html">
            
                    
                    3.3 检测Python模块和包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../chapter3/3.4-chinese.html">
            
                <a href="../chapter3/3.4-chinese.html">
            
                    
                    3.4 检测BLAS和LAPACK数学库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../chapter3/3.5-chinese.html">
            
                <a href="../chapter3/3.5-chinese.html">
            
                    
                    3.5 检测OpenMP的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../chapter3/3.6-chinese.html">
            
                <a href="../chapter3/3.6-chinese.html">
            
                    
                    3.6 检测MPI的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../chapter3/3.7-chinese.html">
            
                <a href="../chapter3/3.7-chinese.html">
            
                    
                    3.7 检测Eigen库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../chapter3/3.8-chinese.html">
            
                <a href="../chapter3/3.8-chinese.html">
            
                    
                    3.8 检测Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../chapter3/3.9-chinese.html">
            
                <a href="../chapter3/3.9-chinese.html">
            
                    
                    3.9 检测外部库:Ⅰ. 使用pkg-config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../chapter3/3.10-chinese.html">
            
                <a href="../chapter3/3.10-chinese.html">
            
                    
                    3.10 检测外部库:Ⅱ. 自定义find模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter4/4.0-chinese.html">
            
                <a href="../chapter4/4.0-chinese.html">
            
                    
                    第4章 创建和运行测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter4/4.1-chinese.html">
            
                <a href="../chapter4/4.1-chinese.html">
            
                    
                    4.1 创建一个简单的单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter4/4.2-chinese.html">
            
                <a href="../chapter4/4.2-chinese.html">
            
                    
                    4.2 使用Catch2库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter4/4.3-chinese.html">
            
                <a href="../chapter4/4.3-chinese.html">
            
                    
                    4.3 使用Google Test库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter4/4.4-chinese.html">
            
                <a href="../chapter4/4.4-chinese.html">
            
                    
                    4.4 使用Boost Test进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter4/4.5-chinese.html">
            
                <a href="../chapter4/4.5-chinese.html">
            
                    
                    4.5 使用动态分析来检测内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter4/4.6-chinese.html">
            
                <a href="../chapter4/4.6-chinese.html">
            
                    
                    4.6 预期测试失败
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../chapter4/4.7-chinese.html">
            
                <a href="../chapter4/4.7-chinese.html">
            
                    
                    4.7 使用超时测试运行时间过长的测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../chapter4/4.8-chinese.html">
            
                <a href="../chapter4/4.8-chinese.html">
            
                    
                    4.8 并行测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../chapter4/4.9-chinese.html">
            
                <a href="../chapter4/4.9-chinese.html">
            
                    
                    4.9 运行测试子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../chapter4/4.10-chinese.html">
            
                <a href="../chapter4/4.10-chinese.html">
            
                    
                    4.10 使用测试固件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter5/5.0-chinese.html">
            
                <a href="../chapter5/5.0-chinese.html">
            
                    
                    第5章 配置时和构建时的操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter5/5.1-chinese.html">
            
                <a href="../chapter5/5.1-chinese.html">
            
                    
                    5.1 使用平台无关的文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter5/5.2-chinese.html">
            
                <a href="../chapter5/5.2-chinese.html">
            
                    
                    5.2 配置时运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter5/5.3-chinese.html">
            
                <a href="../chapter5/5.3-chinese.html">
            
                    
                    5.3 构建时运行自定义命令:Ⅰ. 使用add_custom_command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter5/5.4-chinese.html">
            
                <a href="../chapter5/5.4-chinese.html">
            
                    
                    5.4 构建时运行自定义命令:Ⅱ. 使用add_custom_target
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter5/5.5-chinese.html">
            
                <a href="../chapter5/5.5-chinese.html">
            
                    
                    5.5 构建时为特定目标运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../chapter5/5.6-chinese.html">
            
                <a href="../chapter5/5.6-chinese.html">
            
                    
                    5.6 探究编译和链接命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../chapter5/5.7-chinese.html">
            
                <a href="../chapter5/5.7-chinese.html">
            
                    
                    5.7 探究编译器标志命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../chapter5/5.8-chinese.html">
            
                <a href="../chapter5/5.8-chinese.html">
            
                    
                    5.8 探究可执行命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../chapter5/5.9-chinese.html">
            
                <a href="../chapter5/5.9-chinese.html">
            
                    
                    5.9 使用生成器表达式微调配置和编译
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter6/6.0-chinese.html">
            
                <a href="../chapter6/6.0-chinese.html">
            
                    
                    第6章 生成源码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter6/6.1-chinese.html">
            
                <a href="../chapter6/6.1-chinese.html">
            
                    
                    6.1 配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter6/6.2-chinese.html">
            
                <a href="../chapter6/6.2-chinese.html">
            
                    
                    6.2 使用Python在配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter6/6.3-chinese.html">
            
                <a href="../chapter6/6.3-chinese.html">
            
                    
                    6.3 构建时使用Python生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../chapter6/6.4-chinese.html">
            
                <a href="../chapter6/6.4-chinese.html">
            
                    
                    6.4 记录项目版本信息以便报告
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../chapter6/6.5-chinese.html">
            
                <a href="../chapter6/6.5-chinese.html">
            
                    
                    6.5 从文件中记录项目版本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../chapter6/6.6-chinese.html">
            
                <a href="../chapter6/6.6-chinese.html">
            
                    
                    6.6 配置时记录Git Hash值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../chapter6/6.7-chinese.html">
            
                <a href="../chapter6/6.7-chinese.html">
            
                    
                    6.7 构建时记录Git Hash值
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter7/7.0-chinese.html">
            
                <a href="../chapter7/7.0-chinese.html">
            
                    
                    第7章 构建项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter7/7.1-chinese.html">
            
                <a href="../chapter7/7.1-chinese.html">
            
                    
                    7.1 使用函数和宏重用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter7/7.2-chinese.html">
            
                <a href="../chapter7/7.2-chinese.html">
            
                    
                    7.2 将CMake源代码分成模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter7/7.3-chinese.html">
            
                <a href="../chapter7/7.3-chinese.html">
            
                    
                    7.3 编写函数来测试和设置编译器标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter7/7.4-chinese.html">
            
                <a href="../chapter7/7.4-chinese.html">
            
                    
                    7.4 用指定参数定义函数或宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter7/7.5-chinese.html">
            
                <a href="../chapter7/7.5-chinese.html">
            
                    
                    7.5 重新定义函数和宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../chapter7/7.6-chinese.html">
            
                <a href="../chapter7/7.6-chinese.html">
            
                    
                    7.6 使用废弃函数、宏和变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../chapter7/7.7-chinese.html">
            
                <a href="../chapter7/7.7-chinese.html">
            
                    
                    7.7 add_subdirectory的限定范围
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../chapter7/7.8-chinese.html">
            
                <a href="../chapter7/7.8-chinese.html">
            
                    
                    7.8 使用target_sources避免全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../chapter7/7.9-chinese.html">
            
                <a href="../chapter7/7.9-chinese.html">
            
                    
                    7.9 组织Fortran项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter8/8.0-chinese.html">
            
                <a href="../chapter8/8.0-chinese.html">
            
                    
                    第8章 超级构建模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter8/8.1-chinese.html">
            
                <a href="../chapter8/8.1-chinese.html">
            
                    
                    8.1 使用超级构建模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter8/8.2-chinese.html">
            
                <a href="../chapter8/8.2-chinese.html">
            
                    
                    8.2 使用超级构建管理依赖项:Ⅰ.Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter8/8.3-chinese.html">
            
                <a href="../chapter8/8.3-chinese.html">
            
                    
                    8.3 使用超级构建管理依赖项:Ⅱ.FFTW库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter8/8.4-chinese.html">
            
                <a href="../chapter8/8.4-chinese.html">
            
                    
                    8.4 使用超级构建管理依赖项:Ⅲ.Google Test框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter8/8.5-chinese.html">
            
                <a href="../chapter8/8.5-chinese.html">
            
                    
                    8.5 使用超级构建支持项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter9/9.0-chinese.html">
            
                <a href="../chapter9/9.0-chinese.html">
            
                    
                    第9章 语言混合项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../chapter9/9.1-chinese.html">
            
                <a href="../chapter9/9.1-chinese.html">
            
                    
                    9.1 使用C/C++库构建Fortran项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../chapter9/9.2-chinese.html">
            
                <a href="../chapter9/9.2-chinese.html">
            
                    
                    9.2 使用Fortran库构建C/C++项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../chapter9/9.3-chinese.html">
            
                <a href="../chapter9/9.3-chinese.html">
            
                    
                    9.3 使用Cython构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../chapter9/9.4-chinese.html">
            
                <a href="../chapter9/9.4-chinese.html">
            
                    
                    9.4 使用Boost.Python构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../chapter9/9.5-chinese.html">
            
                <a href="../chapter9/9.5-chinese.html">
            
                    
                    9.5 使用pybind11构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../chapter9/9.6-chinese.html">
            
                <a href="../chapter9/9.6-chinese.html">
            
                    
                    9.6 使用Python CFFI混合C，C++，Fortran和Python
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../chapter10/10.0-chinese.html">
            
                <a href="../chapter10/10.0-chinese.html">
            
                    
                    第10章 编写安装程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../chapter10/10.1-chinese.html">
            
                <a href="../chapter10/10.1-chinese.html">
            
                    
                    10.1 安装项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../chapter10/10.2-chinese.html">
            
                <a href="../chapter10/10.2-chinese.html">
            
                    
                    10.2 生成输出头文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../chapter10/10.3-chinese.html">
            
                <a href="../chapter10/10.3-chinese.html">
            
                    
                    10.3 输出目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../chapter10/10.4-chinese.html">
            
                <a href="../chapter10/10.4-chinese.html">
            
                    
                    10.4 安装超级构建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../chapter11/11.0-chinese.html">
            
                <a href="../chapter11/11.0-chinese.html">
            
                    
                    第11章 打包项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../chapter11/11.1-chinese.html">
            
                <a href="../chapter11/11.1-chinese.html">
            
                    
                    11.1 生成源代码和二进制包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../chapter11/11.2-chinese.html">
            
                <a href="../chapter11/11.2-chinese.html">
            
                    
                    11.2 通过PyPI发布使用CMake/pybind11构建的C++/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../chapter11/11.3-chinese.html">
            
                <a href="../chapter11/11.3-chinese.html">
            
                    
                    11.3 通过PyPI发布使用CMake/CFFI构建C/Fortran/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="../chapter11/11.4-chinese.html">
            
                <a href="../chapter11/11.4-chinese.html">
            
                    
                    11.4 以Conda包的形式发布一个简单的项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.5" data-path="../chapter11/11.5-chinese.html">
            
                <a href="../chapter11/11.5-chinese.html">
            
                    
                    11.5 将Conda包作为依赖项发布给项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../chapter12/12.0-chinese.html">
            
                <a href="../chapter12/12.0-chinese.html">
            
                    
                    第12章 构建文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../chapter12/12.1-chinese.html">
            
                <a href="../chapter12/12.1-chinese.html">
            
                    
                    12.1 使用Doxygen构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../chapter12/12.2-chinese.html">
            
                <a href="../chapter12/12.2-chinese.html">
            
                    
                    12.2 使用Sphinx构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../chapter12/12.3-chinese.html">
            
                <a href="../chapter12/12.3-chinese.html">
            
                    
                    12.3 结合Doxygen和Sphinx
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../chapter13/13.0-chinese.html">
            
                <a href="../chapter13/13.0-chinese.html">
            
                    
                    第13章 选择生成器和交叉编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../chapter13/13.1-chinese.html">
            
                <a href="../chapter13/13.1-chinese.html">
            
                    
                    13.1 使用CMake构建Visual Studio 2017项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.2" data-path="../chapter13/13.2-chinese.html">
            
                <a href="../chapter13/13.2-chinese.html">
            
                    
                    13.2 交叉编译hello world示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3" data-path="../chapter13/13.3-chinese.html">
            
                <a href="../chapter13/13.3-chinese.html">
            
                    
                    13.3 使用OpenMP并行化交叉编译Windows二进制文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="14.0-chinese.html">
            
                <a href="14.0-chinese.html">
            
                    
                    第14章 测试面板
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="14.1-chinese.html">
            
                <a href="14.1-chinese.html">
            
                    
                    14.1 将测试部署到CDash
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="14.2-chinese.html">
            
                <a href="14.2-chinese.html">
            
                    
                    14.2 CDash显示测试覆盖率
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.17.3" data-path="14.3-chinese.html">
            
                <a href="14.3-chinese.html">
            
                    
                    14.3 使用AddressSanifier向CDash报告内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="14.4-chinese.html">
            
                <a href="14.4-chinese.html">
            
                    
                    14.4 使用ThreadSaniiser向CDash报告数据争用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../chapter15/15.0-chinese.html">
            
                <a href="../chapter15/15.0-chinese.html">
            
                    
                    第15章 使用CMake构建已有项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.18.1" data-path="../chapter15/15.1-chinese.html">
            
                <a href="../chapter15/15.1-chinese.html">
            
                    
                    15.1 如何开始迁移项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.2" data-path="../chapter15/15.2-chinese.html">
            
                <a href="../chapter15/15.2-chinese.html">
            
                    
                    15.2 生成文件并编写平台检查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.3" data-path="../chapter15/15.3-chinese.html">
            
                <a href="../chapter15/15.3-chinese.html">
            
                    
                    15.3 检测所需的链接和依赖关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.4" data-path="../chapter15/15.4-chinese.html">
            
                <a href="../chapter15/15.4-chinese.html">
            
                    
                    15.4 复制编译标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.5" data-path="../chapter15/15.5-chinese.html">
            
                <a href="../chapter15/15.5-chinese.html">
            
                    
                    15.5 移植测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.6" data-path="../chapter15/15.6-chinese.html">
            
                <a href="../chapter15/15.6-chinese.html">
            
                    
                    15.6 移植安装目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.7" data-path="../chapter15/15.7-chinese.html">
            
                <a href="../chapter15/15.7-chinese.html">
            
                    
                    15.7 进一步迁移的措施
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.8" data-path="../chapter15/15.8-chinese.html">
            
                <a href="../chapter15/15.8-chinese.html">
            
                    
                    15.8 项目转换为CMake的常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../chapter16/16.0-chinese.html">
            
                <a href="../chapter16/16.0-chinese.html">
            
                    
                    第16章 可能感兴趣的书
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.19.1" data-path="../chapter16/16.1-chinese.html">
            
                <a href="../chapter16/16.1-chinese.html">
            
                    
                    16.1 留下评论——让其他读者知道你的想法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="http://www.bczl.xyz/" target="blank" class="gitbook-link">
            编程之路
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >14.3 使用AddressSanifier向CDash报告内存缺陷</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="143-&#x4F7F;&#x7528;addresssanifier&#x5411;cdash&#x62A5;&#x544A;&#x5185;&#x5B58;&#x7F3A;&#x9677;">14.3 &#x4F7F;&#x7528;AddressSanifier&#x5411;CDash&#x62A5;&#x544A;&#x5185;&#x5B58;&#x7F3A;&#x9677;</h1>
<p><strong>NOTE</strong>:<em>&#x6B64;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x5728; <a href="https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-14/recipe-03" target="_blank">https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-14/recipe-03</a> &#x4E2D;&#x627E;&#x5230;&#xFF0C;&#x5176;&#x4E2D;&#x5305;&#x542B;&#x4E00;&#x4E2A;C++&#x793A;&#x4F8B;&#x548C;&#x4E00;&#x4E2A;Fortran&#x4F8B;&#x5B50;&#x3002;&#x8BE5;&#x793A;&#x4F8B;&#x5728;CMake 3.5&#x7248;(&#x6216;&#x66F4;&#x9AD8;&#x7248;&#x672C;)&#x4E2D;&#x662F;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x5E76;&#x4E14;&#x5DF2;&#x7ECF;&#x5728;GNU/Linux&#x3001;macOS&#x548C;Windows&#x4E0A;&#x8FDB;&#x884C;&#x8FC7;&#x6D4B;&#x8BD5;&#x3002;</em></p>
<p>AddressSanitizer(ASan)&#x662F;&#x53EF;&#x7528;&#x4E8E;C++&#x3001;C&#x548C;Fortran&#x7684;&#x5185;&#x5B58;&#x68C0;&#x6D4B;&#x3002;&#x5B83;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x5185;&#x5B58;&#x7F3A;&#x9677;&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;&#x5728;&#x7A7A;&#x95F2;&#x540E;&#x4F7F;&#x7528;&#x3001;&#x8FD4;&#x56DE;&#x540E;&#x4F7F;&#x7528;&#x3001;&#x4F5C;&#x7528;&#x57DF;&#x540E;&#x4F7F;&#x7528;&#x3001;&#x7F13;&#x51B2;&#x533A;&#x6EA2;&#x51FA;&#x3001;&#x521D;&#x59CB;&#x5316;&#x987A;&#x5E8F;&#x9519;&#x8BEF;&#x548C;&#x5185;&#x5B58;&#x6CC4;&#x6F0F;(&#x8BF7;&#x53C2;&#x89C1;  <a href="https://github.com/google/sanitizers/wiki/AddressSanitizer" target="_blank">https://github.com/google/sanitizers/wiki/AddressSanitizer</a> )&#x3002;&#x4ECE;3.1&#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;AddressSanitizer&#x662F;LLVM&#x7684;&#x4E00;&#x90E8;&#x5206;&#xFF1B;&#x4ECE;4.8&#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x4F5C;&#x4E3A;GCC&#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x52A0;&#x5165;&#x4E24;&#x4E2A;bug&#xFF0C;&#x6B63;&#x5E38;&#x7684;&#x6D4B;&#x8BD5;&#x4E2D;&#x53EF;&#x80FD;&#x65E0;&#x6CD5;&#x68C0;&#x6D4B;&#x5230;&#x3002;&#x4E3A;&#x4E86;&#x68C0;&#x6D4B;&#x8FD9;&#x4E9B;bug&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4F7F;&#x7528;AddressSanitizer&#x5DE5;&#x5177;&#xFF0C;&#x5E76;&#x5C06;CTest&#x4E0E;&#x52A8;&#x6001;&#x5206;&#x6790;&#x7ED3;&#x5408;&#x8D77;&#x6765;&#xFF0C;&#x4ECE;&#x800C;&#x5C06;&#x7F3A;&#x9677;&#x62A5;&#x544A;&#x7ED9;CDash&#x3002;</p>
<h2 id="&#x51C6;&#x5907;&#x5DE5;&#x4F5C;">&#x51C6;&#x5907;&#x5DE5;&#x4F5C;</h2>
<p>&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4F7F;&#x7528;&#x4E24;&#x4E2A;&#x6E90;&#x6587;&#x4EF6;&#x548C;&#x4E24;&#x4E2A;&#x6D4B;&#x8BD5;&#x96C6;&#xFF1A;</p>
<pre><code class="lang-shell">.
&#x251C;&#x2500;&#x2500; CMakeLists.txt
&#x251C;&#x2500;&#x2500; CTestConfig.cmake
&#x251C;&#x2500;&#x2500; dashboard.cmake
&#x251C;&#x2500;&#x2500; src
&#x2502;    &#x251C;&#x2500;&#x2500; buggy.cpp
&#x2502;    &#x251C;&#x2500;&#x2500; buggy.hpp
&#x2502;    &#x2514;&#x2500;&#x2500; CMakeLists.txt
&#x2514;&#x2500;&#x2500; tests
    &#x251C;&#x2500;&#x2500; CMakeLists.txt
    &#x251C;&#x2500;&#x2500; leaky.cpp
    &#x2514;&#x2500;&#x2500; use_after_free.cpp
</code></pre>
<p><code>buggy.cpp</code>&#x5305;&#x542B;&#x6709;&#x4E24;&#x4E2A;bug&#xFF1A;</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;buggy.hpp&quot;</span></span>

<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">function_leaky</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">double</span> *my_array = <span class="hljs-keyword">new</span> <span class="hljs-keyword">double</span>[<span class="hljs-number">1000</span>];
  <span class="hljs-comment">// do some work ...</span>
  <span class="hljs-comment">// we forget to deallocate the array</span>
  <span class="hljs-comment">// delete[] my_array;</span>
  <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">function_use_after_free</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">double</span> *another_array = <span class="hljs-keyword">new</span> <span class="hljs-keyword">double</span>[<span class="hljs-number">1000</span>];
  <span class="hljs-comment">// do some work ...</span>
  <span class="hljs-comment">// deallocate it, good!</span>
  <span class="hljs-keyword">delete</span>[] another_array;
  <span class="hljs-comment">// however, we accidentally use the array</span>
  <span class="hljs-comment">// after it has been deallocated</span>
  <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">&quot;not sure what we get: &quot;</span> &lt;&lt; another_array[<span class="hljs-number">123</span>] &lt;&lt; <span class="hljs-built_in">std</span>::<span class="hljs-built_in">endl</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
</code></pre>
<p>&#x8FD9;&#x4E9B;&#x51FD;&#x6570;&#x5728;&#x76F8;&#x5E94;&#x7684;&#x5934;&#x6587;&#x4EF6;&#x4E2D;&#x58F0;&#x660E;(<code>buggy.hpp</code>&#xFF09;&#xFF1A;</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">pragma</span> once</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">function_leaky</span><span class="hljs-params">()</span></span>;
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">function_use_after_free</span><span class="hljs-params">()</span></span>;
</code></pre>
<p>&#x6D4B;&#x8BD5;&#x6587;&#x4EF6;<code>leaky.cpp</code>&#x4E2D;&#x5C06;&#x4F1A;&#x9A8C;&#x8BC1;<code>function_leaky</code>&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF1A;</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;buggy.hpp&quot;</span></span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">int</span> return_code = function_leaky();
  <span class="hljs-keyword">return</span> return_code;
}
</code></pre>
<p>&#x76F8;&#x5E94;&#x5730;&#xFF0C;<code>use_after_free.cpp</code>&#x4F1A;&#x68C0;&#x67E5;<code>function_use_after_free</code>&#x7684;&#x8FD4;&#x56DE;&#x503C;:</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;buggy.hpp&quot;</span></span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">int</span> return_code = function_use_after_free();
  <span class="hljs-keyword">return</span> return_code;
}
</code></pre>
<h2 id="&#x5177;&#x4F53;&#x5B9E;&#x65BD;">&#x5177;&#x4F53;&#x5B9E;&#x65BD;</h2>
<p>&#x4E3A;&#x4E86;&#x4F7F;&#x7528;ASan&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x7279;&#x5B9A;&#x7684;&#x6807;&#x5FD7;&#x6765;&#x7F16;&#x8BD1;&#x4EE3;&#x7801;&#x3002;&#x7136;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x8FD0;&#x884C;&#x6D4B;&#x8BD5;&#x5E76;&#x5C06;&#x5B83;&#x4EEC;&#x63D0;&#x4EA4;&#x5230;&#x9762;&#x677F;&#x3002;</p>
<ol>
<li><p>&#x751F;&#x6210;bug&#x5E93;&#x7684;&#x5DE5;&#x4F5C;&#x5C06;&#x5728;<code>src/CMakeLists.txt</code>&#x4E2D;&#x5B8C;&#x6210;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_library</span>(buggy <span class="hljs-string">&quot;&quot;</span>)

target_sources(buggy
  PRIVATE
      buggy.cpp
  PUBLIC
      <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>/buggy.hpp
  )

target_include_directories(buggy
  PUBLIC
      <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>
  )
</code></pre>
</li>
<li><p>&#x5728;&#x6587;&#x4EF6;<code>src/CMakeLists.txt</code>&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x9009;&#x9879;&#x7528;&#x4E8E;&#x4F7F;&#x7528;ASan&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">option</span>(ENABLE_ASAN <span class="hljs-string">&quot;Enable AddressSanitizer&quot;</span> <span class="hljs-keyword">OFF</span>)

<span class="hljs-keyword">if</span>(ENABLE_ASAN)
  <span class="hljs-keyword">if</span>(CMAKE_CXX_COMPILER_ID <span class="hljs-keyword">MATCHES</span> GNU)
    <span class="hljs-keyword">message</span>(STATUS <span class="hljs-string">&quot;AddressSanitizer enabled&quot;</span>)
    target_compile_options(buggy
      PUBLIC
          -g -O1 -fsanitize=address -fno-omit-frame-pointer
      )
    <span class="hljs-keyword">target_link_libraries</span>(buggy
      PUBLIC
          asan
      )
  <span class="hljs-keyword">else</span>()
      <span class="hljs-keyword">message</span>(WARNING <span class="hljs-string">&quot;AddressSanitizer not supported for this compiler&quot;</span>)
  <span class="hljs-keyword">endif</span>()
<span class="hljs-keyword">endif</span>()
</code></pre>
</li>
<li><p>&#x6D4B;&#x8BD5;&#x5728;<code>tests/CMakeLists.txt</code>&#x4E2D;&#x5B9A;&#x4E49;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">foreach</span>(_test IN ITEMS leaky use_after_free)
  <span class="hljs-keyword">add_executable</span>(<span class="hljs-variable">${_test}</span> <span class="hljs-variable">${_test}</span>.cpp)
  <span class="hljs-keyword">target_link_libraries</span>(<span class="hljs-variable">${_test}</span> buggy)

  <span class="hljs-keyword">add_test</span>(
    NAME
        <span class="hljs-variable">${_test}</span>
    COMMAND
        $&lt;TARGET_FILE:<span class="hljs-variable">${_test}</span>&gt;
    )
<span class="hljs-keyword">endforeach</span>()
</code></pre>
</li>
<li><p>&#x4E3B;<code>CMakeLists.txt</code>&#x4E0E;&#x4E4B;&#x524D;&#x7684;&#x793A;&#x4F8B;&#x57FA;&#x672C;&#x76F8;&#x540C;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-comment"># set minimum cmake version</span>
<span class="hljs-keyword">cmake_minimum_required</span>(VERSION <span class="hljs-number">3.5</span> FATAL_ERROR)

<span class="hljs-comment"># project name and language</span>
<span class="hljs-keyword">project</span>(recipe-<span class="hljs-number">03</span> LANGUAGES CXX)

<span class="hljs-comment"># require C++11</span>
<span class="hljs-keyword">set</span>(CMAKE_CXX_STANDARD <span class="hljs-number">11</span>)
<span class="hljs-keyword">set</span>(CMAKE_CXX_EXTENSIONS <span class="hljs-keyword">OFF</span>)
<span class="hljs-keyword">set</span>(CMAKE_CXX_STANDARD_REQUIRED <span class="hljs-keyword">ON</span>)

<span class="hljs-comment"># process src/CMakeLists.txt</span>
<span class="hljs-keyword">add_subdirectory</span>(src)
<span class="hljs-keyword">enable_testing</span>()

<span class="hljs-comment"># allow to report to a cdash dashboard</span>
<span class="hljs-keyword">include</span>(CTest)

<span class="hljs-comment"># process tests/CMakeLists.txt</span>
<span class="hljs-keyword">add_subdirectory</span>(tests)
</code></pre>
</li>
<li><p><code>CTestConfig.cmake</code>&#x4E5F;&#x6CA1;&#x6709;&#x4FEE;&#x6539;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CTEST_DROP_METHOD <span class="hljs-string">&quot;http&quot;</span>)
<span class="hljs-keyword">set</span>(CTEST_DROP_SITE <span class="hljs-string">&quot;my.cdash.org&quot;</span>)
<span class="hljs-keyword">set</span>(CTEST_DROP_LOCATION <span class="hljs-string">&quot;/submit.php?project=cmake-cookbook&quot;</span>)
<span class="hljs-keyword">set</span>(CTEST_DROP_SITE_CDASH <span class="hljs-keyword">TRUE</span>)
</code></pre>
</li>
<li><p>&#x8FD9;&#x4E2A;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;CTest&#x811A;&#x672C;&#x5411;CDash&#x63D0;&#x4EA4;&#x7ED3;&#x679C;&#xFF1B;&#x4E3A;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;<code>dashboard.cmake</code>(&#x4E0E;&#x4E3B;<code>CMakeLists.txt</code>&#x548C;<code>` CTestConfig.cmake</code>&#x4F4D;&#x4E8E;&#x540C;&#x4E00;&#x4E2A;&#x76EE;&#x5F55;&#x4E0B;)&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CTEST_PROJECT_NAME <span class="hljs-string">&quot;example&quot;</span>)
cmake_host_system_information(RESULT _site QUERY HOSTNAME)
<span class="hljs-keyword">set</span>(CTEST_SITE <span class="hljs-variable">${_site}</span>)
<span class="hljs-keyword">set</span>(CTEST_BUILD_NAME <span class="hljs-string">&quot;${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}&quot;</span>)

<span class="hljs-keyword">set</span>(CTEST_SOURCE_DIRECTORY <span class="hljs-string">&quot;${CTEST_SCRIPT_DIRECTORY}&quot;</span>)
<span class="hljs-keyword">set</span>(CTEST_BINARY_DIRECTORY <span class="hljs-string">&quot;${CTEST_SCRIPT_DIRECTORY}/build&quot;</span>)

<span class="hljs-keyword">include</span>(ProcessorCount)
ProcessorCount(N)
<span class="hljs-keyword">if</span>(NOT N <span class="hljs-keyword">EQUAL</span> <span class="hljs-number">0</span>)
  <span class="hljs-keyword">set</span>(CTEST_BUILD_FLAGS -j<span class="hljs-variable">${N}</span>)
  <span class="hljs-keyword">set</span>(ctest_test_args <span class="hljs-variable">${ctest_test_args}</span> PARALLEL_LEVEL <span class="hljs-variable">${N}</span>)
<span class="hljs-keyword">endif</span>()

ctest_start(Experimental)

ctest_configure(
  OPTIONS
      -DENABLE_ASAN:BOOL=<span class="hljs-keyword">ON</span>
  )

ctest_build()
ctest_test()

<span class="hljs-keyword">set</span>(CTEST_MEMORYCHECK_TYPE <span class="hljs-string">&quot;AddressSanitizer&quot;</span>)
ctest_memcheck()

ctest_submit()
</code></pre>
</li>
<li><p>&#x6211;&#x4EEC;&#x5C06;&#x6267;&#x884C;<code>dashboard.cmake</code>&#x811A;&#x672C;&#x3002;&#x6CE8;&#x610F;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;<code>CTEST_CMAKE_GENERATOR</code>&#x4E0E;&#x751F;&#x6210;&#x5668;&#x9009;&#x9879;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-shell">$ ctest -S dashboard.cmake -D 

CTEST_CMAKE_GENERATOR=&quot;Unix Makefiles&quot;
Each . represents 1024 bytes of output
. Size of output: 0K
Each symbol represents 1024 bytes of output.
&apos;!&apos; represents an error and &apos;*&apos; a warning.
. Size of output: 1K
</code></pre>
</li>
<li><p>&#x7ED3;&#x679C;&#x5C06;&#x4F1A;&#x51FA;&#x73B0;&#x5728;CDash&#x7F51;&#x7AD9;&#x4E0A;:</p>
<p><img src="../../images/chapter14/14-6.png" alt=""></p>
</li>
</ol>
<h2 id="&#x5177;&#x4F53;&#x5B9E;&#x65BD;">&#x5177;&#x4F53;&#x5B9E;&#x65BD;</h2>
<p>&#x8FD9;&#x4E2A;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x6210;&#x529F;&#x5730;&#x5411;&#x4EEA;&#x8868;&#x677F;&#x7684;&#x52A8;&#x6001;&#x5206;&#x6790;&#x90E8;&#x5206;&#x62A5;&#x544A;&#x4E86;&#x5185;&#x5B58;&#x9519;&#x8BEF;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6D4F;&#x89C8;&#x7F3A;&#x9677;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#xFF0C;&#x5F97;&#x5230;&#x8FDB;&#x4E00;&#x6B65;&#x7684;&#x4E86;&#x89E3;:</p>
<p><img src="../../images/chapter14/14-7.png" alt=""></p>
<p>&#x901A;&#x8FC7;&#x5355;&#x51FB;&#x5404;&#x4E2A;&#x94FE;&#x63A5;&#xFF0C;&#x53EF;&#x4EE5;&#x6D4F;&#x89C8;&#x5B8C;&#x6574;&#x4FE1;&#x606F;&#x7684;&#x8F93;&#x51FA;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;&#x672C;&#x5730;&#x751F;&#x6210;AddressSanitizer&#x62A5;&#x544A;&#x3002;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x8BBE;&#x7F6E;<code>ENABLE_ASAN</code>:</p>
<pre><code class="lang-shell">$ mkdir -p build
$ cd build
$ cmake -DENABLE_ASAN=ON ..
$ cmake --build .
$ cmake --build . --target test

Start 1: leaky
1/2 Test #1: leaky ............................***Failed 0.07 sec
Start 2: use_after_free
2/2 Test #2: use_after_free ...................***Failed 0.04 sec
0% tests passed, 2 tests failed out of 2
</code></pre>
<p>&#x8FD0;&#x884C;<code>leaky</code>&#x6D4B;&#x8BD5;&#xFF0C;&#x76F4;&#x63A5;&#x4EA7;&#x751F;&#x4EE5;&#x4E0B;&#x7ED3;&#x679C;:</p>
<pre><code class="lang-shell">$ ./build/tests/leaky

=================================================================
==18536==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8000 byte(s) in 1 object(s) allocated from:
#0 0x7ff984da1669 in operator new[](unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cc:82
#1 0x564925c93fd2 in function_leaky() /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/src/buggy.cpp:7
#2 0x564925c93fb2 in main /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/tests/leaky.cpp:4
#3 0x7ff98403df49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)
SUMMARY: AddressSanitizer: 8000 byte(s) leaked in 1 allocation(s).
</code></pre>
<p>&#x76F8;&#x5E94;&#x5730;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8FD0;&#x884C;<code>use_after_free</code>&#xFF0C;&#x5F97;&#x5230;&#x8BE6;&#x7EC6;&#x7684;&#x8F93;&#x51FA;:</p>
<pre><code class="lang-shell">$ ./build/tests/use_after_free

=================================================================
==18571==ERROR: AddressSanitizer: heap-use-after-free on address 0x6250000004d8 at pc 0x557ffa8b0102 bp 0x7ffe8c560200 sp 0x7ffe8c5601f0
READ of size 8 at 0x6250000004d8 thread T0
#0 0x557ffa8b0101 in function_use_after_free() /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/src/buggy.cpp:28
#1 0x557ffa8affb2 in main /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/tests/use_after_free.cpp:4
#2 0x7ff1d6088f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)
#3 0x557ffa8afec9 in _start (/home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/build/tests/use_after_free+0xec9)
0x6250000004d8 is located 984 bytes inside of 8000-byte region [0x625000000100,0x625000002040)
freed by thread T0 here:
#0 0x7ff1d6ded5a9 in operator delete[](void*) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cc:128
#1 0x557ffa8afffa in function_use_after_free() /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/src/buggy.cpp:24
#2 0x557ffa8affb2 in main /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/tests/use_after_free.cpp:4
#3 0x7ff1d6088f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)
previously allocated by thread T0 here:
#0 0x7ff1d6dec669 in operator new[](unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cc:82
#1 0x557ffa8affea in function_use_after_free() /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/src/buggy.cpp:19
#2 0x557ffa8affb2 in main /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/tests/use_after_free.cpp:4
#3 0x7ff1d6088f49 in __libc_start_main (/usr/lib/libc.so.6+0x20f49)
SUMMARY: AddressSanitizer: heap-use-after-free /home/user/cmake-recipes/chapter-14/recipe-03/cxx-example/src/buggy.cpp:28 in function_use_after_free()
Shadow bytes around the buggy address:
0x0c4a7fff8040: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff8050: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff8060: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff8070: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff8080: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=&gt;0x0c4a7fff8090: fd fd fd fd fd fd fd fd fd fd fd[fd]fd fd fd fd
0x0c4a7fff80a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff80b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff80c0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff80d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c4a7fff80e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==18571==ABORTING
</code></pre>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5728;&#x6CA1;&#x6709;AddressSanitizer&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FDB;&#x884C;&#x6D4B;&#x8BD5;(&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;<code>ENABLE_ASAN</code>&#x662F;&#x5173;&#x95ED;&#x7684;)&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x62A5;&#x544A;&#x9519;&#x8BEF;&#xFF1A;</p>
<pre><code class="lang-shell">$ mkdir -p build_no_asan
$ cd build_no_asan
$ cmake ..
$ cmake --build .
$ cmake --build . --target test

Start 1: leaky
1/2 Test #1: leaky ............................ Passed 0.00 sec
Start 2: use_after_free
2/2 Test #2: use_after_free ................... Passed 0.00 sec
100% tests passed, 0 tests failed out of 2
</code></pre>
<p>&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x6CC4;&#x6F0F;&#x53EA;&#x4F1A;&#x6D6A;&#x8D39;&#x5185;&#x5B58;&#xFF0C;&#x800C;<code>use_after_free</code>&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x672A;&#x5B9A;&#x4E49;&#x884C;&#x4E3A;&#x3002;&#x8C03;&#x8BD5;&#x8FD9;&#x4E9B;&#x95EE;&#x9898;&#x7684;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;&#x662F;&#x4F7F;&#x7528;valgrind (<a href="http://valgrind.org" target="_blank">http://valgrind.org</a> )&#x3002;</p>
<p>&#x4E0E;&#x524D;&#x4E24;&#x4E2A;&#x793A;&#x4F8B;&#x76F8;&#x53CD;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4E86;CTest&#x811A;&#x672C;&#x6765;&#x914D;&#x7F6E;&#x3001;&#x6784;&#x5EFA;&#x548C;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#xFF0C;&#x5E76;&#x5C06;&#x62A5;&#x544A;&#x63D0;&#x4EA4;&#x5230;&#x9762;&#x677F;&#x3002;&#x8981;&#x4E86;&#x89E3;&#x6B64;&#x793A;&#x4F8B;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#xFF0C;&#x8BF7;&#x4ED4;&#x7EC6;&#x67E5;&#x770B;<code>dashboard.cmake</code>&#x811A;&#x672C;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x9879;&#x76EE;&#x540D;&#x79F0;&#x5E76;&#x8BBE;&#x7F6E;&#x4E3B;&#x673A;&#x62A5;&#x544A;&#x548C;&#x6784;&#x5EFA;&#x540D;&#x79F0;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CTEST_PROJECT_NAME <span class="hljs-string">&quot;example&quot;</span>)
cmake_host_system_information(RESULT _site QUERY HOSTNAME)
<span class="hljs-keyword">set</span>(CTEST_SITE <span class="hljs-variable">${_site}</span>)
<span class="hljs-keyword">set</span>(CTEST_BUILD_NAME <span class="hljs-string">&quot;${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}&quot;</span>)
</code></pre>
<p>&#x6211;&#x4EEC;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;<code>CTEST_BUILD_NAME</code>&#x7684;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;&#x662F;<code>Linux-x86_64</code>&#x3002;&#x4E0D;&#x540C;&#x7684;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E0B;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x89C2;&#x5BDF;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<p>&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x4E3A;&#x6E90;&#x548C;&#x6784;&#x5EFA;&#x76EE;&#x5F55;&#x6307;&#x5B9A;&#x8DEF;&#x5F84;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CTEST_SOURCE_DIRECTORY <span class="hljs-string">&quot;${CTEST_SCRIPT_DIRECTORY}&quot;</span>)
<span class="hljs-keyword">set</span>(CTEST_BINARY_DIRECTORY <span class="hljs-string">&quot;${CTEST_SCRIPT_DIRECTORY}/build&quot;</span>)
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x751F;&#x6210;&#x5668;&#x8BBE;&#x7F6E;&#x4E3A;<code>Unix Makefile</code>:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CTEST_CMAKE_GENERATOR <span class="hljs-string">&quot;Unix Makefiles&quot;</span>)
</code></pre>
<p>&#x4F46;&#x662F;&#xFF0C;&#x5BF9;&#x4E8E;&#x66F4;&#x5177;&#x53EF;&#x79FB;&#x690D;&#x6027;&#x7684;&#x6D4B;&#x8BD5;&#x811A;&#x672C;&#xFF0C;&#x6211;&#x4EEC;&#x66F4;&#x613F;&#x610F;&#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x884C;&#x63D0;&#x4F9B;&#x751F;&#x6210;&#x5668;:</p>
<pre><code class="lang-shell">$ ctest -S dashboard.cmake -D CTEST_CMAKE_GENERATOR=&quot;Unix Makefiles&quot;
</code></pre>
<p><code>dashboard.cmake</code>&#x4E2D;&#x7684;&#x4E0B;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x7247;&#x6BB5;&#xFF0C;&#x5C06;&#x8BA1;&#x7B97;&#x51FA;&#x673A;&#x5668;&#x4E0A;&#x53EF;&#x7528;&#x7684;CPU&#x82AF;&#x6570;&#x91CF;&#xFF0C;&#x5E76;&#x5C06;&#x6D4B;&#x8BD5;&#x6B65;&#x9AA4;&#x7684;&#x5E76;&#x884C;&#x7EA7;&#x8BBE;&#x7F6E;&#x4E3A;&#x53EF;&#x7528;CPU&#x82AF;&#x6570;&#x91CF;&#xFF0C;&#x4EE5;&#x4F7F;&#x603B;&#x6D4B;&#x8BD5;&#x65F6;&#x95F4;&#x6700;&#x5C0F;&#x5316;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">include</span>(ProcessorCount)
ProcessorCount(N)
<span class="hljs-keyword">if</span>(NOT N <span class="hljs-keyword">EQUAL</span> <span class="hljs-number">0</span>)
    <span class="hljs-keyword">set</span>(CTEST_BUILD_FLAGS -j<span class="hljs-variable">${N}</span>)
    <span class="hljs-keyword">set</span>(ctest_test_args <span class="hljs-variable">${ctest_test_args}</span> PARALLEL_LEVEL <span class="hljs-variable">${N}</span>)
<span class="hljs-keyword">endif</span>()
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;&#x6B65;&#x9AA4;&#x5E76;&#x914D;&#x7F6E;&#x4EE3;&#x7801;&#xFF0C;&#x5C06;<code>ENABLE_ASAN</code>&#x8BBE;&#x7F6E;&#x4E3A;<code>ON</code>:</p>
<pre><code class="lang-cmake">ctest_start(Experimental)

ctest_configure(
  OPTIONS
      -DENABLE_ASAN:BOOL=<span class="hljs-keyword">ON</span>
  )
</code></pre>
<p><code>dashboard.cmake</code>&#x5176;&#x4ED6;&#x547D;&#x4EE4;&#x4E3A;&#x6620;&#x5C04;&#x5230;&#x6784;&#x5EFA;&#x3001;&#x6D4B;&#x8BD5;&#x3001;&#x5185;&#x5B58;&#x68C0;&#x67E5;&#x548C;&#x63D0;&#x4EA4;&#x6B65;&#x9AA4;:</p>
<pre><code class="lang-cmake">ctest_build()
ctest_test()

<span class="hljs-keyword">set</span>(CTEST_MEMORYCHECK_TYPE <span class="hljs-string">&quot;AddressSanitizer&quot;</span>)

ctest_memcheck()
ctest_submit()
</code></pre>
<h2 id="&#x66F4;&#x591A;&#x4FE1;&#x606F;">&#x66F4;&#x591A;&#x4FE1;&#x606F;</h2>
<p>&#x7EC6;&#x5FC3;&#x7684;&#x8BFB;&#x8005;&#x4F1A;&#x6CE8;&#x610F;&#x5230;&#xFF0C;&#x5728;&#x94FE;&#x63A5;&#x76EE;&#x6807;&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x5728;&#x7CFB;&#x7EDF;&#x4E0A;&#x641C;&#x7D22;AddressSanitizer&#x3002;&#x5B9E;&#x9645;&#x4E2D;&#xFF0C;&#x5E93;&#x67E5;&#x627E;&#x5DE5;&#x4F5C;&#x5DF2;&#x7ECF;&#x63D0;&#x524D;&#x505A;&#x5B8C;&#xFF0C;&#x4EE5;&#x907F;&#x514D;&#x5728;&#x94FE;&#x63A5;&#x9636;&#x6BB5;&#x51FA;&#x73B0;&#x610F;&#x5916;&#x3002;</p>
<p>&#x6709;&#x5173;AddressSanitizer&#x6587;&#x6863;&#x548C;&#x793A;&#x4F8B;&#x7684;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#xFF0C;&#x8BF7;&#x53C2;&#x89C1;<a href="https://github.com/google/sanitizers/wiki/AddressSanitizer" target="_blank">https://github.com/google/sanitizers/wiki/AddressSanitizer</a> &#x3002;AddressSanitizer&#x5E76;&#x4E0D;&#x4EC5;&#x9650;&#x4E8E;C&#x548C;C++&#x3002;&#x5BF9;&#x4E8E;Fortran&#x793A;&#x4F8B;&#xFF0C;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x53C2;&#x8003; <a href="https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-14/recipe-03/fortran-example" target="_blank">https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-14/recipe-03/fortran-example</a> &#x3002;</p>
<p><strong>NOTE</strong>:<em>&#x53EF;&#x4EE5;&#x5728;<a href="https://github.com/arsenm/sanitizers-cmake" target="_blank">https://github.com/arsenm/sanitizers-cmake</a> &#x4E0A;&#x627E;&#x5230;CMake&#x7A0B;&#x5E8F;&#xFF0C;&#x7528;&#x6765;&#x67E5;&#x627E;&#x6740;&#x6BD2;&#x7A0B;&#x5E8F;&#x548C;&#x8C03;&#x6574;&#x7F16;&#x8BD1;&#x5668;&#x6807;&#x5FD7;</em></p>
<p>&#x4E0B;&#x9762;&#x7684;&#x535A;&#x5BA2;&#x6587;&#x7AE0;&#x8BA8;&#x8BBA;&#x4E86;&#x5982;&#x4F55;&#x6DFB;&#x52A0;&#x5BF9;&#x52A8;&#x6001;&#x5206;&#x6790;&#x5DE5;&#x5177;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x5BF9;&#x6211;&#x4EEC;&#x5F88;&#x6709;&#x542F;&#x53D1;&#x6027;&#xFF1A;<a href="https://blog.kitware.com/ctest-cdash-add-support-for-new-dynamic-analysis-tools/" target="_blank">https://blog.kitware.com/ctest-cdash-add-support-for-new-dynamic-analysis-tools/</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="14.2-chinese.html" class="navigation navigation-prev " aria-label="Previous page: 14.2 CDash显示测试覆盖率">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="14.4-chinese.html" class="navigation navigation-next " aria-label="Next page: 14.4 使用ThreadSaniiser向CDash报告数据争用">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"14.3 使用AddressSanifier向CDash报告内存缺陷","level":"1.17.3","depth":2,"next":{"title":"14.4 使用ThreadSaniiser向CDash报告数据争用","level":"1.17.4","depth":2,"path":"content/chapter14/14.4-chinese.md","ref":"content/chapter14/14.4-chinese.md","articles":[]},"previous":{"title":"14.2 CDash显示测试覆盖率","level":"1.17.2","depth":2,"path":"content/chapter14/14.2-chinese.md","ref":"content/chapter14/14.2-chinese.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro","-sharing","github","pageview-count"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/arcticfox1919"},"search-pro":{},"pageview-count":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"陈晓伟 chenxiaowei","pdf":{"pageNumbers":false,"fontSize":30,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":30,"left":30,"top":30,"bottom":50}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《CMake Cookbook》中文版","language":"zh-hans","gitbook":"*","description":"作为对《CMake Cookbook》英文版的中文翻译。","direction":"ltr"},"file":{"path":"content/chapter14/14.3-chinese.md","mtime":"2020-09-22T10:39:01.913Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-22T11:21:21.825Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

